﻿
using Cysharp.Threading.Tasks;
using UnityEngine.Networking;

namespace Client.Base
{
    public class FsmRequsetPatchInfo : PatchState
    {

        public FsmRequsetPatchInfo(PatchProcess process) : base(process)
        {

        }

        public override async void OnEnter()
        {
            this.Log("[Patch] FsmRequsetPatchInfo.");
            if (Process.IsSimulation)
            {
                YAPackageInfo.SetPackageSetting(new YAPackageSetting
                {
                    remoteURL = "http://192.168.6.233/ugf",
                    remoteVersion = "1.0",
                });
                Process.TryTransition<FsmInitPackage>();
            }
            else
            {
                using (var wwww = new UnityWebRequest(Process.Url, "POST"))
                {
                    //todo
                    await wwww.SendWebRequest().ToUniTask();
                    if (wwww.result != UnityWebRequest.Result.Success)
                    {
                        Process.Call(Event_PatchError.EVENT_PATCHERROR, new Event_PatchError
                        {
                            status = 1401,
                            message = $"请求补丁信息失败 : {wwww.error}"
                        });
                    }
                }
            }


        }
    }

}
